
var express = require('express');
var bodyParser = require('body-parser');
var app  = express();

app.listen(8000);
var tweets = [];
app.get('/',function(req,res){
	// res.send('welcome to node twitter');
	var title ="welcome",
		header="welcome to express world!";
	res.render('index',{
		locals:{
			'title':tilte,
			'header':header,
			'tweets':tweets,
			stylesheets:['/public/style.css']
		}
	})
});

app.post('/send',bodyParser.urlencoded({ extended:true}),function(req,res){
	if (req.body && req.body.tweet) {
        tweets.push(req.body.tweet)
        res.send({status:"ok", message:"Tweet received"})
      } else {
// 没有 tweet ?
        res.send({status:"nok", message:"No tweet received"})
      }
	})

app.get('/tweets',function(req,res){
	res.send(tweets);
})
